<style lang="scss">
  @import 'index';
</style>

<template>
  <div class="ga-container">
    <div class="ga-user-order">
      <!--tab-->
      <ul class="ga-tab gCell">
        <!--<li class="item active">全部</li>-->
        <li class="item" :class="{active : activeIndex == index}" v-for="(item,index) in tabs" :key="index" @click="tab(index)">{{item}}</li>
      </ul>
      <!--tab-->

      <!--order-list-->
      <ul class="order-list">
        <li class="item" v-for="(item,index) in orderlist" :key="index">
         <!-- <div class="state">订单号：{{item.order_sn}}</div> --> <div class="state">{{item.order_status_txt}}</div>

          <a class="product" href="#" v-for="(value,key) in item._order_goods" :key="key">
            <div class="item-media">
              <image class="img" mode="aspectFill" :src="value.goods_icon"></image>
            </div>
            <div class="item-inner">
              <div class="inner1">
                <p class="p p1">{{value.goods_name}}</p>
                <p class="p p2">{{value.goods_attr ? value.goods_attr : ''}}</p>
              </div>
              <div class="inner2">
                 <p class="p p3">¥{{value.goods_price}}</p>
                 <p class="p p4">¥{{value.market_price}}</p>
                 <p class="p p5">x{{value.goods_number}}</p>
              </div>
            </div>
          </a>

          <div class="total">
            <span class="span">共{{item._order_goods_total}}件商品</span>
            <span class="span">合计:¥{{item.order_amount}}</span>
            <span class="span">(含运费¥{{item.shipping_price}})</span>
          </div>

          <div class="opera">
            <a class="span" :href="'/pages/orderDetail/main?id='+item.id">订单详情</a>
            <a class="span" v-if="item.pay_status == 0" :href="'/pages/pay/main?id=' + item.id">立即支付</a>
            <span class="span" v-if="item.pay_status == 1 && item.shipping_status == 0" @click="tixing">提醒发货</span>
            <span class="span" v-if="item.pay_status == 1 && item.shipping_status == 1" @click="receive(item.id)">确认收货</span>
            <span class="span" v-if="item.shipping_status == 2 && item.evaluate_status == 0" @click="pingjia(item.id)">商品评价</span>
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import {isLogin,showToast} from '@/utils/handleLogin'
export default {
  data () {
    return {
      tabs: ["全部", "待支付" ,'已付款' ,'已发货' ,'已完成'],
      activeIndex: 0,
      orderlist: []
    }
  },
  methods:{
    tab(index){
      this.activeIndex = index;
      this.load()
    },
    async load () {
      let params = {}
      if(this.activeIndex){
         params.status = this.activeIndex
      }
      this.$_util.ajax.post('https://guo-a.com/mapi/order/orderlist?token=' + this.$store.state.Token,params).then((res) => {
         console.log(res)
         if(res.code === 200){
           this.orderlist = res.data
         }
      })
    },
    /*确认收货*/
    async receive (id) {
        let params = {
           id: id
        }
        this.$_util.ajax.post('https://guo-a.com/mapi/order/receive?token=' + this.$store.state.Token,params).then((res)=>{
          if(res.code === 200){
            this.load()
          }
        })
    },
    tixing () {
      showToast('提醒成功')
      setTimeout(function(){
          this.load()
      },500)
    },
    pingjia (id) {
      this.bindNavigateTo('../orderComment/main?id='+ id)
    },
    /**
     * 路由跳转
     */
    bindNavigateTo (url) {
        wx.navigateTo({
          url
        })
    },
    bindSwitchTab (url) {
        wx.switchTab({
          url
        })
    }
  },
  onLoad () {

  },
  onShow () {
    isLogin(() => {
      this.orderlist = []
      if(this.$root.$mp.query.hasOwnProperty('status')){
        this.activeIndex = this.$root.$mp.query.status
          this.load()
      }
    })
  },
  mounted () {

  }
}
</script>
